#include<iostream>
#include<string>
#include<set>
#include<cmath>
using namespace std;

char arr[12][12];
set<int>hashval;
struct state{
    int cx,cy,cd;
    int mx,my,md;
};
state my_state;

bool my_hash(state&s){
    int my_val=s.cx*pow(12,0)+s.cy*pow(12,1)+s.cd*pow(12,2)+
                s.mx*pow(12,3)+s.my*pow(12,4)+s.md*pow(12,5);
    
    //cout<<my_val<<endl;
    if(hashval.count(my_val)) return true;
    hashval.insert(my_val);
    if(hashval.empty())return false;
    
    
    return false;
}

void next1(){
    if(my_state.cd==0){
        my_state.cd=1;
        if(my_state.cx==1){return;}
        if(arr[my_state.cx-1][my_state.cy]=='*')return;
        my_state.cx-=1;
        my_state.cd=0;
    }
    else if(my_state.cd==1){
        my_state.cd=2;
        if(my_state.cy==10){return;}
        if(arr[my_state.cx][my_state.cy+1]=='*')return;
        my_state.cy+=1;
        my_state.cd=1;
    }
    else if(my_state.cd==2){
        my_state.cd=3;
        if(my_state.cx==10){return;}
        if(arr[my_state.cx+1][my_state.cy]=='*')return;
        my_state.cx+=1;
        my_state.cd=2;
    }
    else if(my_state.cd==3){
        my_state.cd=0;
        if(my_state.cy==1){return;}
        if(arr[my_state.cx][my_state.cy-1]=='*')return;
        my_state.cy-=1;
        my_state.cd=3;
    }


}

void next2(){
    if(my_state.md==0){
        my_state.md=1;
        if(my_state.mx==1){return;}
        if(arr[my_state.mx-1][my_state.my]=='*')return;
        my_state.mx-=1;
        my_state.md=0;
    }
    else if(my_state.md==1){
        my_state.md=2;
        if(my_state.my==10){return;}
        if(arr[my_state.mx][my_state.my+1]=='*')return;
        my_state.my+=1;
        my_state.md=1;
    }
    else if(my_state.md==2){
        my_state.md=3;
        if(my_state.mx==10){return;}
        if(arr[my_state.mx+1][my_state.my]=='*')return;
        my_state.mx+=1;
        my_state.md=2;
    }
    else if(my_state.md==3){
        my_state.md=0;
        if(my_state.my==1){return;}
        if(arr[my_state.mx][my_state.my-1]=='*')return;
        my_state.my-=1;
        my_state.md=3;
    }
}

int main(){
    string str;
    for(int i=1;i<=10;i++){
        cin>>str;
        for(int j=1;j<=10;j++){
            if(str[j-1]=='C'){
                str[j-1]='.';
                my_state.cx=i;
                my_state.cy=j;
                my_state.cd=0;
            }
            if(str[j-1]=='F'){
                str[j-1]='.';
                my_state.mx=i;
                my_state.my=j;
                my_state.md=0;
            }
            arr[i][j]=str[j-1];
        }
    }
    

    int step=0;
    while(1){
        
        
        if(my_state.cx==my_state.mx&&my_state.cy==my_state.my){
            cout<<step<<endl;
            return 0;
        }
        bool result=my_hash(my_state);
        if(result){
            cout<<0<<endl;
            return 0;
        }
        step=step+1;
        next1();
        next2();
        state s=my_state;
        //printf("%d %d %d %d %d %d\n",s.cx, s.cy,s.cd,s.mx,s.my,s.md);
    }

}